<?php

namespace app\index\service;

use app\index\dao\AccessLogDao;

/**
 * Class AccessService
 * @package app\index\service
 */
class AccessService
{
    // dao
    private AccessLogDao $accessLogDao;

    public function __construct(AccessLogDao $accessLogDao)
    {
        $this->accessLogDao = $accessLogDao;
    }

    /**
     * 插入访问记录
     * @param $referer
     * @param $pagePath
     * @param $ip
     * @param $memberId
     * @param string $pf 客户端类型
     * @param string $chain 链路
     * @param int $promotionGroupId 推广小组
     * @return void
     */
    public function add($referer, $pagePath, $ip, $memberId, $pf, $chain, $promotionGroupId): void
    {
        $time = time();

        $params['referer'] = $referer;
        $params['pagePath'] = $pagePath;
        $params['ip'] = $ip;
        $params['memberId'] = $memberId;
        $params['pf'] = $pf;
        $params['chain'] = $chain;
        $params['promotionGroupId'] = $promotionGroupId;
        $params['date'] = date('Y-m-d', $time);
        $params['time'] = date('H:i:s', $time);
        $params['created'] = $time;

        try {
            $this->accessLogDao->insertActive($params, []);
        } catch (\Exception $e) {

        }
    }

}
